let data = require('./poem.js');
let webpack = require('webpack');
let extractTextPlugin = require('extract-text-webpack-plugin');
let htmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
    entry: __dirname + '/src/js/index.js',
    output: {
        path: __dirname + '/dist',
        filename: '[name].js'
    },
    module: {
        rules: [{
            test: /\.js$/,
            use: ['babel-loader']
        }, {
            test: /\.scss$/,
            use: extractTextPlugin.extract({
                fallback: 'style-loader',
                use: ['css-loader', 'sass-loader']
            })
        }, {
            test: /\.(jpg|png|svg)$/,
            use: ['file-loader']
        }]
    },
    devServer: {
        port: 8080,
        open: true,
        before(app) {
            app.get('/api/list', function(req, res, next) {
                res.json({ code: 1, data: data })
            })
        }
    },
    plugins: [
        new extractTextPlugin('styles.css'),
        new htmlWebpackPlugin({
            template: './src/index.html',
            filename: 'index.html',
        }),
        new webpack.HotModuleReplacementPlugin({})
    ]
}